<?php

class Ms_Form_User extends Zend_Dojo_Form
{

    public function init()
    {
        $this->setMethod('post');
        
        // 用户名
        $userName = $this->createElement('TextBox', 'username');
        $userName->setLabel('用户名：');
        $userName->setRequired(TRUE);     
        $userName->addValidator('stringLength', false, array(5, 20));
        $userName->addErrorMessage('用户名要求英文5-20个字母或2-6个汉字。');
        $this->addElement($userName);
        
        // 密码
        $password = $this->createElement('PasswordTextBox', 'password');
        $password->setLabel('密码：');
        $password->setRequired(TRUE);
        $password->addValidator('stringLength', false, array(6));
        $password->addErrorMessage('密码要求至少6个字符。');
        $this->addElement($password);
        
        // 确认密码
        $password2 = $this->createElement('PasswordTextBox', 'password2');
        $password2->setLabel('确认密码：');
        $password2->setRequired(TRUE);
        $password2->addValidator('identical', false, array('token' => 'password')); // 验证两个密码是否相同
        $password2->addErrorMessage('两次输入的密码密不相同');
        $this->addElement($password2);
        
        // 性别
        $sex = $this->createElement('RadioButton', 'sex');
        $sex->setLabel('用户性别：');
        $sex->addMultiOptions(array(1=>'男', 0=>'女'));
        $sex->setSeparator("");
        $this->addElement($sex);
        
        // 电子邮件
        $email = $this->createElement('TextBox', 'email');
        $email->setLabel('电子邮箱：');
        $email->addValidator('EmailAddress');
        $email->addErrorMessage('请输入一个有效的email地址。');
        $this->addElement($email);
        
        // 个人简介
        $profile = $this->createElement('Textarea', 'profile');
        $profile->setLabel('个人简介：');
        $profile->setAttribs(array('rows'=>4, 'cols'=>50));
        $this->addElement($profile);
        
        
        // 用户头像
        $avatar = $this->createElement('file', 'avatar');
        $avatar->setLabel('用户头像：');
        $this->addElement($avatar);
        
        // 用户状态
        $status = $this->createElement('FilteringSelect', 'status');
        $status->setLabel('用户状态');
        $status->addMultiOptions(array(
            '1'=>'激活',
            '0'=>'锁定',
        ));
        $this->addElement($status);
        
        // 用户角色
        $role = $this->createElement('FilteringSelect', 'role');
        $role->setLabel('选择角色：');
        $role->addMultiOptions(array(
            'user'=>'用户',
            'student'=>'学生',
            'teacher'=>'教师',
            'author'=>'作者',
            'editor'=>'编辑',
            'admin'=>'管理员'
        ));
        $role->setRequired(TRUE);
        $this->addElement($role);
        
        // 提交按钮
        $submit = $this->createElement('SubmitButton', 'submit', array('label'=>'提交', 'ignore' => true));
        $this->addElement($submit);
        
    }

}
